<template>
  <div>
    <div class="DIS">
      <div class="left">
        <el-input style="margin-top:-15px;left: 400px" class="serchContent"  placeholder="请输入搜索内容" prefix-icon="el-icon-search"></el-input>
        <el-button  class="serch" type="primary"  icon="el-icon-search">搜索</el-button>
      </div>
    <div class="tableStu">
      <div>
      <el-table :data="Course" height="100%" border class="table" >
        <el-table-column prop="tname" label="申请教师" width="120">
        </el-table-column>
        <el-table-column prop="level" label="年级" width="120">
        </el-table-column>
        <el-table-column prop="name" label="申请课程" width="120">
        </el-table-column>
        <el-table-column prop="week" label="申请时间" width="80">
        </el-table-column>
        <el-table-column prop="time" width="80">
        </el-table-column>
        <el-table-column prop="time_class" label="课程时长" width="100">
        </el-table-column>
        <el-table-column prop="loc" label="课程所在省" width="120">
        </el-table-column>
        <el-table-column prop="info" label="课程信息" width="180">
        </el-table-column>
        <el-table-column prop="max_num" label="最大容纳人数" width="120">
        </el-table-column>
        <el-table-column prop="allow" label="状态" width="130">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="140">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-check" circle @click="approveYes(scope.$index,scope.row)"></el-button>
            <el-button type="danger" icon="el-icon-close" circle @click="approveNo(scope.$index,scope.row)">
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
  </div>
</div>
</template>

<script>
export default {
  methods: {
    getTime() {
      let date = new Date();
      let seperator1 = "-";
      let seperator2 = ":";
      //以下代码依次是获取当前时间的年月日时分秒
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let strDate = date.getDate();
      let minute = date.getMinutes();
      let hour = date.getHours();
      let second = date.getSeconds();
      //固定时间格式
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      if (hour >= 0 && hour <= 9) {
        hour = "0" + hour;
      }
      if (minute >= 0 && minute <= 9) {
        minute = "0" + minute;
      }
      if (second >= 0 && second <= 9) {
        second = "0" + second;
      }
      return year + seperator1 + month + seperator1 + strDate
        + " " + hour + seperator2 + minute + seperator2 + second;
    },

    approveYes(index,row){
      if(row.allow=="已通过"||row.allow=="未通过"){
         this.$message({
           showClose: true,
           message: '该课程已被审批'
         });
       }

      if(row.allow=="请求删除"){
         let _this = this
         this.$axios({
             method:"GET",
             url:"http://localhost/course/deleteYes/"+row.id
         }).then(result => {
           this.$message({
             showClose: true,
             message: '成功审批！',
             type: 'success'
           });
           _this.action()
         })
      }

       if(row.allow=="修改中"){
         let _this=this
         this.$axios({
           method:"GET",
           url:"http://localhost/course/approve/"+row.id+"/"+"已通过"
         }).then(response => {
           this.$message({
             showClose: true,
             message: '成功审批！',
             type: 'success'
           });
           _this.action()
           _this.$axios({
             method:"GET",
             url:"http://localhost/TecCorMes/save/"+row.tid+"/"+row.id+"/"+"已通过"
           }).then(result => {

           })
         })
       }

      if(row.allow=="未审批"){
         let _this=this
         this.$axios({
           method:"GET",
           url:"http://localhost/course/approve/"+row.id+"/"+"已通过"
         }).then(response => {
           this.$message({
             showClose: true,
             message: '成功审批！',
             type: 'success'
           });
           _this.action()
           let date_create=_this.getTime()
           _this.$axios({
             method:"GET",
             url:"http://localhost/course/transTime/"+row.id+"/"+date_create
           }).then(result => {

           })
         })


         this.$axios({
            method:"GET",
            url:"http://localhost/TecCorMes/save/"+row.tid+"/"+row.id+"/"+"已通过"
         }).then(result => {

         })
       }

    },

    approveNo(index,row){
      if(row.allow=="已通过"||row.allow=="未通过"){
        this.$message({
          showClose: true,
          message: '该课程已被审批'
        });
      }

      if(row.allow=="请求删除"){
        let _this = this
        this.$axios({
          method:"GET",
          url:"http://localhost/course/deleteNo/"+row.id
        }).then(result => {
          this.$message({
            showClose: true,
            message: '成功审批！',
            type: 'success'
          });
          _this.action()
        })
      }

      if(row.allow=="修改中"){
        let _this=this
        this.$axios({
          method:"GET",
          url:"http://localhost/course/returnCopy/"+row.id
        }).then(result => {
          _this.returnCor=result.data;
          _this.$axios({
            method:"POST",
            url:"http://localhost/course/approveUpdateNo/",
            data:{
               id:_this.returnCor.id,
               name:_this.returnCor.name,
               level:_this.returnCor.level,
               week:_this.returnCor.week,
               time:_this.returnCor.time,
               loc:_this.returnCor.loc,
               info:_this.returnCor.info,
               max_num:_this.returnCor.max_num,
               copyid:_this.returnCor.copyid,
            }

          }).then(result1 => {
             _this.$axios({
                method:"GET",
                url:"http://localhost/course/deleteCopy/"+row.id
             }).then(result2 => {
               this.$message({
                 showClose: true,
                 message: '成功审批！',
                 type: 'success'
               });
               _this.action()
               _this.$axios({
                 method:"GET",
                 url:"http://localhost/TecCorMes/save/"+row.tid+"/"+row.id+"/"+"未通过"
               }).then(result => {

               })
             })
          })
        })


      }
      if(row.allow=="未审批"){
        let _this=this
        this.$axios({
          method:"GET",
          url:"http://localhost/course/approve/"+row.id+"/"+"未通过"
        }).then(response => {
          this.$message({
            showClose: true,
            message: '成功审批！',
            type: 'success'
          });
          _this.action()
        })

        this.$axios({
          method:"GET",
          url:"http://localhost/TecCorMes/save/"+row.tid+"/"+row.id+"/"+"未通过"
        }).then(result => {

        })

      }

    },



    action() {
      let _this = this
      this.$axios({
        method: 'GET',
        url: 'http://localhost/course/findAll',
      }).then(response => {
        _this.Course=response.data
      })
    },

    setYes(index,row){
      let _this = this
      this.$axios({
        method: 'GET',
        url: 'http://localhost/student_course/setYes/'+row.sid+'/'+row.cid+'/'+_this.getTime(),
      }).then(response => {
        this.$message({
          type: 'success',
          message: '操作成功!',
        });
        _this.action();
      })

      _this.$axios({
        method:'POST',
        url:'http://localhost/student/saveMes',
        data:{
          sid:row.sid,
          cid:row.cid,
          allow:"已通过",
        }
      }).then(response => {

      })



      _this.$axios({
        method:"GET",
        url:"http://localhost/course/addOne/"+row.cid
      }).then(response => {

      })
    },

    setNo(index,row){
      let _this = this
      this.$axios({
        method: 'GET',
        url: 'http://localhost/student_course/setNo/'+row.sid+'/'+row.cid+'/'+_this.getTime(),
      }).then(response => {
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
        _this.action();
      })
      _this.$axios({
        method:"GET",
        url:"http://localhost/course/subOne/"+row.cid
      }).then(response => {

      })

      _this.$axios({
        method:'POST',
        url:'http://localhost/student/saveMes',
        data:{
          sid:row.sid,
          cid:row.cid,
          allow:"未通过",
        }
      }).then(response => {

      })

    }
  },




  mounted() {
    this.action()
  },
  data() {
    return {
      Course: [],
      retrunCor:'',
    }
  },


}
</script>

<style scoped>
.elInput {
  display: inline;
}

.tableStu {
  position: absolute;
  height: 80%;
  width: 85.8%
}

.DIS {
  display: flex;
  height: 50px;
  justify-content: space-between;
}

.left {
  display: flex;
  flex-direction: row;
  height: 40px;
}

.serch {
  position: relative;
  top:5px;
  left: 400px;
  margin-left: 20px;
}

.serchContent {
  position: relative;
  top:-40px;
  margin-left: 20px;
}

.add {
  position: relative;
  top: -55px;
  left: 730px;
}

.table{
  position: absolute;
  width: 100%;
  height: 100%;
}
</style>
